<template>
  <div style="display: inline-block;">
    <el-button style="margin-bottom:10px" type="primary" class="buttoncss" icon="el-icon-edit" circle title="编辑" @click="dialogTable()"/>
    <el-dialog v-el-drag-dialog :visible.sync="dialogTableVisible" title="修改" @close="close">
      <el-form ref="row_data" label-position="left" label-width="110px" style="width: 400px; margin-left:50px;">
        <el-form-item :label="'id'" prop="id">
          <el-input v-model="row_data.id" :disabled="true" placeholder="id"/>
        </el-form-item>
        <el-form-item :label="'商家名称'" prop="merchantName">
          <el-input v-model="row_data.merchantName" :disabled="true" placeholder="商家名称"/>
        </el-form-item>
        <el-form-item label="标签" prop="tags">
          <el-select v-model="row_data.tags_id" :multiple-limit="length" multiple style="width: 100%" placeholder="标签">
            <el-option
              v-for="item in tags"
              :key="item.id"
              :label="item.title"
              :value="item.id"/>
          </el-select>
        </el-form-item>
        <el-form-item :label="'后台账号'" prop="adminAccount">
          <el-input v-model="row_data.adminAccount" :disabled="true" placeholder="后台账号"/>
        </el-form-item>
        <el-form-item :label="'启用后台'" prop="status">
          <el-select v-model="row_data.admin_status" placeholder="是否启用后台" clearable style="width: 290px;" class="filter-item">
            <el-option
              v-for="item in adminStatus"
              :key="item.value"
              :label="item.label"
              :value="item.value"/>
          </el-select>
        </el-form-item>
        <el-form-item :label="'启用商城'" prop="adminPassword">
          <el-select v-model="row_data.status" placeholder="使用启用商城" clearable style="width: 290px;" class="filter-item">
            <el-option
              v-for="item in shopStatus"
              :key="item.value"
              :label="item.label"
              :value="item.value"/>
          </el-select>
        </el-form-item>
        <el-form-item :label="'修改支付密码'" prop="paymentCode">
          <el-input v-model="row_data.paymentCode" type="password" placeholder="修改支付密码"/>
        </el-form-item>
        <el-form-item :label="'确认支付密码'" prop="paymentCode2">
          <el-input v-model="row_data.paymentCode2" type="password" placeholder="确认支付密码"/>
        </el-form-item>
        <el-form-item :label="'修改后台密码'" prop="adminPassword">
          <el-input v-model="row_data.adminPassword" type="password" placeholder="修改后台密码"/>
        </el-form-item>
        <el-form-item :label="'确认后台密码'" prop="adminPassword2">
          <el-input v-model="row_data.adminPassword2" type="password" placeholder="确认后台密码"/>
        </el-form-item>
        <el-form-item :label="'操作密码'" prop="operatingPassword">
          <el-input v-model="row_data.operatingPassword" type="password" placeholder="请输入账号操作密码"/>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="submitForm()">编辑</el-button>
          <el-button @click="close()">取消</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>

<script>
import elDragDialog from '@/directive/el-dragDialog' // base on element-ui
import store from '@/store'
import { edit, tags } from '@/api/merchant/merchant'
import Tinymce from '@/components/Tinymce'
export default {
  name: 'DragDialogDemo',
  directives: { elDragDialog },
  components: { Tinymce },
  props: {
    row_data: {
      type: Object,
      // 对象或数组默认  值必须从一个工厂函数获取
      default: function() {
        return null
      }
    }
  },
  data() {
    return {
      dialogTableVisible: false,
      operatingPassword: '',
      paymentCode2: '',
      adminPassword2: '',
      adminStatus: [
        {
          value: 0,
          label: '否'
        }, {
          value: 1,
          label: '是'
        }
      ],
      shopStatus: [
        {
          value: 0,
          label: '否'
        }, {
          value: 1,
          label: '是'
        }
      ],
      tags: [],
      length: 5,
      tabs: []
    }
  },
  created: function() {
    tags(store.getters.token).then(res => {
      this.tags = res.data.list
    })
    console.log(this.row_data)
  },
  methods: {
    dialogTable() {
      this.dialogTableVisible = true
      console.log('tags', this.tags)
      console.log('hahhah', this.row_data)
      // console.log('hahhah', this.row_data.tags)
      // debugger
      // const tage = this.row_data.tags.split(',')
      // const tag = []
      // tage.forEach(v => {
      //   tag.push(parseInt(v))
      // })
      // this.row_data.tags = tag
    },
    submitForm() {
      edit(store.getters.token, this.row_data).then(res => {
        if (res.data.status) {
          this.$message({
            type: 'success',
            message: res.data.msg
          })
          this.close()
        } else {
          this.$message({
            type: 'error',
            message: res.data.msg
          })
        }
        // this.close()
      })
    },
    close() {
      this.$emit('getLists')
      this.dialogTableVisible = false
    }
  }
}
</script>
